<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of button
 *
 * @author Chris Sim
 */

Yii::import('zii.widgets.jui.CJuiInputWidget');

class button extends CJuiInputWidget {
    //put your code here

    public $options = array(
                            'icon'=>'',
                            'label'=>'',
                            'click'=>'',
                            'items'=>array(),
                            );
                            
    public function run() {
        // publish files
        list($name,$id)=$this->resolveNameID();
        $basePath=Yii::getPathOfAlias('application.widgets.button.script');
	$this->scriptUrl=Yii::app()->getAssetManager()->publish($basePath);
	Yii::app()->getClientScript()->registerCssFile($this->scriptUrl.'/button.css');
        $this->registerScriptFile('button.js', CClientScript::POS_HEAD);
        // end
        $this->htmlOptions['class'] = empty($this->htmlOptions['class'])?'extendbutton ui-state-default ui-corner-all':$this->htmlOptions['class'] .' extendbutton ui-state-default ui-corner-all';
        $this->htmlOptions['id'] = $id;
        $this->htmlOptions['href'] = "javascript:void(0);";
        $content = empty($this->options['icon'])?'':"<span class=\"ui-icon {$this->options['icon']}\"></span>";
        $content .= $this->options['label'];
        $html = CHtml::tag('div', array('class'=>'extendbutton'), CHtml::tag('a', $this->htmlOptions, $content));
        $options=CJavaScript::encode($this->options);
        $js = "$('#{$id}').extendButton({$options});";
        
        Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id, $js, CClientScript::POS_READY);
        echo $html;
    }
    private function LoadItems($items=array(),$html='') {
        if(count(items)<=0)
            return $html;
            
    }
}
?>
